package com.lee.boot.head.first.demo.mongo.controller;


import com.lee.boot.head.first.demo.entity.Student;
import com.lee.boot.head.first.demo.mongo.dao.StudentDao;
import com.lee.boot.head.first.demo.mongo.dao.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/student")
public class StudentController {
    @Autowired
    StudentDao studentDao;

    //    @Autowired
    StudentRepository studentRepository;


    @RequestMapping(value = "/save")
    public void saveStudent(Student student) {
        studentDao.saveStudent(student);
    }


    @RequestMapping(value = "/update")
    public void updateStudent(Student student) {
        studentDao.updateStudent(student);
    }

    @RequestMapping(value = "/delete/{id}")
    public void deleteStudentById(@PathVariable Long id) {
        studentDao.deleteStudentById(id);
    }


    @RequestMapping(value = "/list")
    public List<Student> getStudents() {
        List<Student> students = studentDao.getStudents();
        return students;
    }

//    @RequestMapping(value = "/age")
//    public List<Student> getStudentByAge(Integer start, Integer end) {
//        return studentRepository.listByAge(start, end);
//    }

}
